Skip to content

test(rivetkit): avoid polling sleep actor awake#4783

Closed
NathanFlurry wants to merge 1 commit intographite-base/4783from
driver-fixes/sleep-db-poll-interval
Closed

test(rivetkit): avoid polling sleep actor awake#4783
NathanFlurry wants to merge 1 commit intographite-base/4783from
driver-fixes/sleep-db-poll-interval

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 26, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 26, 2026

PR Review: test(rivetkit): avoid polling sleep actor awake

Overview

This is a small, focused fix to a flaky driver test in actor-sleep-db.test.ts. The test "scheduled action stays awake until db work completes" was polling the actor every 50 ms to assert that sleepCount and startCount reach their expected values, but each poll is itself an actor action that resets the idle sleep timer, preventing the actor from ever sleeping and making the assertion impossible to satisfy.

The fix:

  1. Increases the timeout from 5,000 ms to 10,000 ms (matching the waitForAction default).
  2. Widens the interval from 50 ms to SLEEP_DB_TIMEOUT + 250 ms (1,250 ms), ensuring the actor has enough idle time between polls to actually sleep and trigger the state change under test.

Code Quality

  • Correct root-cause fix. Tight polling that keeps an actor awake while waiting for idle sleep is exactly the class of flake described in CLAUDE.md: "Driver tests that wait for actor sleep must not poll actor actions while waiting; each action counts as activity and can reset the sleep deadline." This PR follows that guideline precisely.
  • Comment is clear and accurate. The added comment explains why the interval must be loose, which is non-obvious and exactly the kind of comment the project style guide asks for.
  • vi.waitFor comment convention. The adjacent // comment sits on the immediately preceding line of the interval option, satisfying the pnpm run check:wait-for-comments convention for vi.waitFor calls.

Suggestions / Minor Nits

  • First-iteration immediate call. vi.waitFor fires the callback once immediately before applying the interval, so the actor is contacted once at entry even with the new wide interval. The pre-vi.waitFor hard wall-clock delay (await waitFor(...) around line 197) is intended to let the actor sleep before polling begins. If sleep is still pending when polling starts, that first immediate action could reset the deadline. In practice the pre-wait delay (approximately 2,550 ms for SLEEP_DB_TIMEOUT = 1000) should be sufficient, but it is a subtle ordering dependency worth a follow-up comment.
  • Timeout increase lacks justification in the PR description. A brief note such as "doubled to give at least one full SLEEP_DB_TIMEOUT cycle between polls within the overall window" would help future readers.
  • No other sleep-sensitive vi.waitFor calls in this file use a tight 50 ms interval, so no additional changes are needed elsewhere.

Verdict

Looks good. The fix is correct, minimal, well-commented, and matches the project testing conventions. The new timeout and interval values are well-reasoned. This is a draft PR so the unchecked checklist items are expected.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 26, 2026

Preview packages published to npm

Install with:

npm install rivetkit@pr-4783

All packages published as 0.0.0-pr.4783.e589ddb with tag pr-4783.

Engine binary is shipped via @rivetkit/engine-cli on linux-x64-musl, linux-arm64-musl, darwin-x64, and darwin-arm64. Windows users should use the release installer or set RIVET_ENGINE_BINARY.

Docker images:

docker pull rivetdev/engine:slim-e589ddb
docker pull rivetdev/engine:full-e589ddb
Individual packages
npm install rivetkit@pr-4783
npm install @rivetkit/react@pr-4783
npm install @rivetkit/rivetkit-napi@pr-4783
npm install @rivetkit/workflow-engine@pr-4783

@claude
Copy link
Copy Markdown

claude Bot commented Apr 26, 2026

Review

This fix is correct and directly addresses the flakiness described by CLAUDE.md's rule:

Driver tests that wait for actor sleep must not poll actor actions while waiting; each action counts as activity and can reset the sleep deadline.

With SLEEP_DB_TIMEOUT = 1000ms, polling at 50ms intervals was calling actor.getCounts() far too frequently. Each call registered as actor activity and kept resetting the idle sleep timer, preventing the actor from ever sleeping and making the test flaky.

The fix

Setting interval: SLEEP_DB_TIMEOUT + 250 (= 1250ms) gives the actor a full sleep window between polls. The timeout bump to 10_000ms is appropriate — with a 1250ms interval you only get ~8 attempts, so the window needs to accommodate at least a couple of cycles.

Comment placement

The script at scripts/check-wait-for-comments.ts checks that the immediately preceding line before await vi.waitFor( is a // comment. Line 201 satisfies that requirement — the new in-options comment is additional documentation and does not conflict with the linting rule.

Observation — similar pattern at line 1020

This block also waits for a sleep-count assertion (sleepCount, startCount) while polling with interval: 50. Each getStatus()/getLogEntries() call is an actor action that could prevent the actor from sleeping. If that test becomes flaky for the same reason, the same interval fix would apply.

Summary

The change is small, correct, and well-explained. No issues with CLAUDE.md conventions. Ready to merge once the draft is opened.

This was referenced Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant